﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufButtonControl.h"

namespace gnuf {
    
    class Toolbar;
    class Tab;

    class QtTabBar;
    class GNUF_BASE_EXPORT TabBar final
        : public ItemWith<QtTabBar>
    {
        CANNOT_COPY_OR_ASSIGN(TabBar);
        
    public:
        static const EItemType Type;
        explicit TabBar(Toolbar *);
        virtual ~TabBar();
        Tab * addTab(const std::wstring &, const std::vector< const Info * > &, const gcmp::Any & userData, const std::wstring& toolTip = L"");
        void removeTab(const Tab *);
        void deactivateTab(const Tab *);
        typedef std::list< gcmp::OwnerPtr< Tab > > Tabs;
        typedef std::vector< Tab * > RawTabs;
        inline const Tabs & tabs() const { return m_tabs; }
        inline const Tabs & deactiveTabs() const { return m_deactiveTabs; }
        RawTabs rawTabs();
        RawTabs rawDeactiveTabs();
        const Tab * currentTab() const;

        int indexOf(const Tab *) const;
        void setCurrentIndex(const int index, const bool wantToDispatchEvent = true);
        void swapTab(const int from,const int to);
        inline int currentIndex() const { return m_currentIndex; }
        const gcmp::OwnerPtr< Info > & showMoreInfo() const {
            return m_showMoreInfo;
        }

        void setWorkable(bool);
        bool workable() const { return m_workable; }
    protected:
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;

    private:
        TabBar::Tabs m_tabs, m_deactiveTabs;
        gcmp::OwnerPtr< Info > m_showMoreInfo;
        int m_currentIndex;
        bool m_workable;
    };

    class QtTab;
    class GNUF_BASE_EXPORT Tab final
        : public ItemWith<QtTab>
    {
        CANNOT_COPY_OR_ASSIGN(Tab);

    public:
        static const EItemType Type;
        explicit Tab(TabBar *);
        virtual ~Tab();

        int index() const;

        inline void setCaption(const std::wstring &);
        inline const std::wstring & caption() const {
            return m_caption;
        }

        inline void setToolTip(const std::wstring&);
        inline const std::wstring& toolTip() const {
            return m_toolTip;
        }

        typedef std::vector< const Info * > Buttons;
        inline void addButtons(const Buttons & buttons) {
            m_buttons = buttons;
        }
        inline const Buttons & buttons() const {
            return m_buttons;
        }

        void setSelected(bool);
        bool selected() const { return m_selected; }

    protected:
        // Inherits from Item...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAppearanceSettingChanged() override;
        virtual void onPostAbilityChanged() override;
        virtual QtItem * getQtItem() const override;

    private:
        std::wstring m_caption;
        std::wstring m_toolTip;
        Buttons m_buttons;
        bool m_selected;
    };
}
